//
//  MeReplyController.m
//  ZDAudioProcessing
//
//  Created by zhibao on 2023/9/28.
//

#import "MyReplyController.h"
@interface MyReplyController (){
    NSArray *contentArray;
    NSMutableArray *btns;
    NSInteger selectIndex;
}

@end

@implementation MyReplyController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.gk_navBackgroundColor = MyColor(@"#02185A");
    self.view.backgroundColor = MyColor(@"#02185A");
    self.gk_backImage = [UIImage imageNamed:@"arrow_back_white"];
    selectIndex = -1;
    btns = [NSMutableArray new];
    [self getData];
}

-(void)getData{
    [[HttpHelper sharedInstance] sendGet:@"api/product" parameters:@{@"type":@"-1"} success:^(NSURLSessionTask * _Nonnull operation, ResponseModel * _Nonnull responseObject) {
        if(responseObject.code == 1){
            self->contentArray = responseObject.data[@"data"];
            if(self->contentArray.count > 0){
                self->selectIndex = 0;
            }
            [self initView];
        }
    } failure:^(NSURLSessionTask * _Nonnull operation, NSError * _Nonnull error) {
        
    }];
}

-(void)initView{
    UIScrollView *scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, NAVIH, MY_Screen_W, MY_Screen_H - NAVIH - 45 - 12 - SafeBottomMargin - 20)];
    scrollview.backgroundColor = MyColor(@"#02185A");
    scrollview.showsVerticalScrollIndicator = NO;
    [self.view addSubview:scrollview];
    
    UIImageView *topImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"me_pay_top"]];
    [scrollview addSubview:topImgView];
    [topImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).offset(-15);
        make.top.mas_equalTo(0);
        make.width.mas_equalTo(282);
        make.height.mas_equalTo(182);
    }];
    
    
    UILabel *nameLabel = [UILabel new];
    nameLabel.font = MY_SCALE_RegularFONT(25);
    nameLabel.text = LocalizedString(@"VIP会员");
    nameLabel.textColor = UIColor.whiteColor;
    nameLabel.lineBreakMode = NSLineBreakByWordWrapping;
    nameLabel.numberOfLines = 0;
    [scrollview addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(35);
        make.top.equalTo(scrollview).offset(15);
        make.right.equalTo(self.view).offset(-35);
    }];
    
    UILabel *detailLabel1 = [UILabel new];
    detailLabel1.font = MY_SCALE_RegularFONT(15);
    detailLabel1.text = LocalizedString(@"畅享VIP带来的体验");
    detailLabel1.textColor = UIColor.whiteColor;
    [scrollview addSubview:detailLabel1];
    detailLabel1.lineBreakMode = NSLineBreakByWordWrapping;
    detailLabel1.numberOfLines = 0;
    [detailLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(nameLabel);
        make.top.equalTo(nameLabel.mas_bottom).offset(10);
    }];
    
    UIView *tempView;
    for (int i = 0; i < contentArray.count; i ++) {
        UIButton *view = [UIButton buttonWithType:UIButtonTypeCustom];
        //view.frame = CGRectMake(25, bgView.top + 20 + (60 + 15) * i, MY_Screen_W - 50, 60);
        view.layer.cornerRadius = 15;
        view.layer.borderColor = MyColor(@"#027AFF").CGColor;
        view.layer.borderWidth = 0.5;
        view.tag = 1000 + i;
        [view addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [scrollview addSubview:view];
        [btns addObject:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(25);
            if(tempView){
                make.top.equalTo(tempView.mas_bottom).offset(15);
            }else{
                make.top.equalTo(detailLabel1.mas_bottom).offset(49);
            }
            make.right.equalTo(self.view).offset(-25);
            make.height.mas_equalTo(60);
        }];
        tempView = view;
        
        UILabel *titleLabel = [UILabel new];
        titleLabel.font = MY_SCALE_RegularFONT(15);
        titleLabel.tag = 10000;
        titleLabel.numberOfLines = 0;
        titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [view addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.bottom.equalTo(view);
            make.right.mas_equalTo(-80);
        }];
        
        UILabel *moneyLabel = [UILabel new];
        moneyLabel.font = MY_SCALE_SemiboldFONT(18);
        moneyLabel.tag = 10001;
        moneyLabel.textAlignment = NSTextAlignmentRight;
        moneyLabel.text = [NSString stringWithFormat:@"￥%@",contentArray[i][@"price"]];
        [view addSubview:moneyLabel];
        [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15);
            make.top.bottom.equalTo(view);
        }];
        moneyLabel.textColor = MyColor(@"#ffffff");
        titleLabel.textColor = MyColor(@"#ffffff");
        
        NSArray *products = [IAPShare sharedHelper].iap.products;
        for (SKProduct *product in products) {
            if([product.productIdentifier isEqualToString:contentArray[i][@"product_id"]]){
                if([[IAPShare sharedHelper].iap getLocalePrice:product]){
                    moneyLabel.text = [NSString stringWithFormat:@"%@",[[IAPShare sharedHelper].iap getLocalePrice:product]];
                }else{
                    if(i == 0){
                        moneyLabel.text = @"￥128.00";
                    }else if(i == 1){
                        moneyLabel.text = @"￥98.00";
                    }else if(i == 2){
                        moneyLabel.text = @"￥38.00";
                    }else if(i == 3){
                        moneyLabel.text = @"￥18.00";
                    }
                }
                if(product.localizedTitle.length > 2){
                    titleLabel.text = product.localizedTitle;
                }else{
                    if(i == 0){
                        titleLabel.text = LocalizedString(@"终身会员");
                    }else if(i == 1){
                        titleLabel.text = LocalizedString(@"连续包年");
                    }else if(i == 1){
                        titleLabel.text = LocalizedString(@"连续包月");
                    }else if(i == 2){
                        titleLabel.text = LocalizedString(@"连续包周");
                    }
                }
                //detailLabel.text = product.localizedDescription;
            }
        }
        
        if(i == 0){
            view.backgroundColor = MyColor(@"#027AFF");
        }else{
            view.backgroundColor = MyColor(@"#465A95");
        }
    }
    
    UILabel *tipDetailLabel = [UILabel new];
    tipDetailLabel.font = MY_SCALE_RegularFONT(12);
    tipDetailLabel.textColor = MyColor(@"#7586B8");
    tipDetailLabel.text = LocalizedString(@"到期自动续订，可随时取消订阅");
    tipDetailLabel.numberOfLines = 0;
    tipDetailLabel.lineBreakMode = NSLineBreakByWordWrapping;
    [scrollview addSubview:tipDetailLabel];
    [tipDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(42);
        make.top.equalTo(tempView.mas_bottom).offset(12);
        make.right.equalTo(self.view).offset(-25);
    }];
    
    UIImageView *tipImgView = [UIImageView new];
    tipImgView.image = [UIImage imageNamed:@"me_pay_tip"];
    [scrollview addSubview:tipImgView];
    [tipImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25);
        make.centerY.equalTo(tipDetailLabel);
        make.width.height.mas_equalTo(12);
    }];
    
    //自动续费服务说明
    UILabel *ctipLabel = [UILabel new];
    ctipLabel.font = MY_SCALE_SemiboldFONT(17);
    ctipLabel.textColor = UIColor.whiteColor;
    ctipLabel.text = LocalizedString(@"会员特权");
    [scrollview addSubview:ctipLabel];
    ctipLabel.numberOfLines = 0;
    ctipLabel.lineBreakMode = NSLineBreakByWordWrapping;
    tempView = ctipLabel;
    [ctipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25);
        make.top.equalTo(tipDetailLabel.mas_bottom).offset(23);
        make.right.equalTo(self.view).offset(-25);
    }];
    
    NSArray *tequanArray = @[
        @{@"title":LocalizedString(@"无限制生成照片水印"),@"img":@"me_pay_zhaopian"},
        @{@"title":LocalizedString(@"无限制生成视频水印"),@"img":@"me_pay_shipin"},
        @{@"title":LocalizedString(@"无限制生成拼接图片水印"),@"img":@"me_pay_pinjie"},
    ];
    
    for (int i = 0; i < tequanArray.count; i ++) {
        UILabel *label = [[UILabel alloc]init];
        label.text = tequanArray[i][@"title"];
        label.textColor = UIColor.whiteColor;
        label.numberOfLines = 0;
        label.lineBreakMode = NSLineBreakByWordWrapping;
        label.font = MY_SCALE_RegularFONT(16);
        [scrollview addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(47);
            make.right.equalTo(self.view).offset(-25);
            make.top.equalTo(tempView.mas_bottom).offset(18);
        }];
        
        UIImageView *imgView = [UIImageView new];
        imgView.image = [UIImage imageNamed:tequanArray[i][@"img"]];
        [scrollview addSubview:imgView];
        [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.centerY.equalTo(label);
            make.width.height.mas_equalTo(22);
        }];
        
        tempView = label;
    }
    
    
    UIView *bgView = [UIView new];
    bgView.backgroundColor = MyColor(@"#102461");
    bgView.layer.cornerRadius = 10;
    [scrollview addSubview:bgView];
    [scrollview insertSubview:bgView aboveSubview:topImgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.equalTo(self.view).offset(-10);
        make.top.equalTo(detailLabel1.mas_bottom).offset(29);
        make.bottom.equalTo(tempView.mas_bottom).offset(20);
    }];
    
    UILabel *cclabel = [[UILabel alloc]init];
    cclabel.text = LocalizedString(@"自动续费服务说明");
    cclabel.textColor = MyColor(@"#D4D4D4");
    cclabel.font = MY_SCALE_RegularFONT(11);
    cclabel.numberOfLines = 0;
    cclabel.lineBreakMode = NSLineBreakByWordWrapping;
    [scrollview addSubview:cclabel];
    [cclabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.equalTo(self.view).offset(-20);
        make.top.equalTo(tempView.mas_bottom).offset(45);
    }];
    tempView = cclabel;
    YYLabel *tipLabel = [[YYLabel alloc]init];
    [scrollview addSubview:tipLabel];
    NSMutableString *string =[[NSMutableString alloc]initWithString: LocalizedString(@"付款将在确认购买时从iTunes帐户中扣除。除非在当前期间结束前至少24小时关闭自动续订，否则订阅会自动续订。帐户将在当前期间结束前24小时内收取续订费用，并确定续订费用。您可以在AppStore的账户设置中管理您的订阅，并关闭自动续订。当您通过免费试用注册订阅时，您的订阅会立即开始，但在免费试用期结束之前不会向您收费。\n\n")];
    [string appendString:@"    "];
    [string appendString:LocalizedString(@"用户协议")];
    [string appendString:@"       "];
    [string appendString:LocalizedString(@"隐私协议")];
    [string appendString:@"       "];
    [string appendString:LocalizedString(@"订阅协议")];
    [string appendString:@"       "];
    [string appendString:LocalizedString(@"恢复购买")];
    [string appendString:@"    "];
    NSRange yhrange = [string rangeOfString:LocalizedString(@"用户协议")];
    NSRange xyrange = [string rangeOfString:LocalizedString(@"隐私协议")];
    NSRange dyrange = [string rangeOfString:LocalizedString(@"订阅协议")];
    NSRange hfrange = [string rangeOfString:LocalizedString(@"恢复购买")];
    NSMutableAttributedString *atti =[[NSMutableAttributedString alloc]initWithString:string];
    atti.yy_font = MY_SCALE_RegularFONT(11);
    atti.yy_color = MyColor(@"#D4D4D4");
    atti.yy_lineSpacing = 5;
    tipLabel.numberOfLines = 0;
    tipLabel.preferredMaxLayoutWidth = MY_Screen_W - 40;
    tipLabel.lineBreakMode = NSLineBreakByWordWrapping;
    [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.equalTo(self.view).offset(-20);
        make.top.equalTo(tempView.mas_bottom).offset(10);
        make.bottom.equalTo(scrollview).offset(-25);
    }];
    
    [atti yy_setTextHighlightRange:NSMakeRange(yhrange.location - 1, yhrange.length + 2) color:UIColor.whiteColor backgroundColor:UIColor.clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        WebViewController *controller = [[WebViewController alloc] initWithtitle:LocalizedString(@"用户协议") WithUrl:@"https://docs.qq.com/doc/DRll6a01QaWNiclZE"];
        [[MYGlobal share].lastVC.navigationController pushViewController:controller animated:YES];
    }];
     YYTextDecoration *decoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@(0.5) color:[UIColor whiteColor]];
     [atti yy_setTextUnderline:decoration range:yhrange];
    
    [atti yy_setTextHighlightRange:NSMakeRange(xyrange.location - 1, xyrange.length + 2) color:UIColor.whiteColor backgroundColor:UIColor.clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        WebViewController *controller = [[WebViewController alloc] initWithtitle:LocalizedString(@"隐私协议") WithUrl:@"https://docs.qq.com/doc/DRmxCb3NSTUF2YnFm"];
        [[MYGlobal share].lastVC.navigationController pushViewController:controller animated:YES];
    }];
    
    YYTextDecoration *xydecoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@(0.5) color:[UIColor whiteColor]];
    [atti yy_setTextUnderline:xydecoration range:xyrange];
    
    [atti yy_setTextHighlightRange:NSMakeRange(hfrange.location - 1, hfrange.length + 2) color:UIColor.whiteColor backgroundColor:UIColor.clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        [QMUITips showLoading:LocalizedString(@"查询中...") inView:self.view];
        [[IAPShare sharedHelper].iap restoreProductsWithCompletion:^(SKPaymentQueue *payment, NSError *error) {
            
            //check with SKPaymentQueue
            
            // number of restore count
            int numberOfTransactions = payment.transactions.count;
            [QMUITips hideAllTips];
            if(numberOfTransactions < 1){
                [QMUITips showError:LocalizedString(@"无可恢复购买的项目!")];
                return;
            }
            DLog(@"numberOfTransactions==%d",numberOfTransactions);
            BOOL  flag = NO;
            for (SKPaymentTransaction *transaction in payment.transactions)
            {
                if(transaction.transactionState == SKPaymentTransactionStateRestored && flag == NO){
                    flag = YES;
                    NSString *purchased = transaction.payment.productIdentifier;
                    DLog(@"purchased==%@",purchased);
                    [self verifyPurchaseWithPaymentTransaction:transaction];
                }
            }
        }];
    }];
    YYTextDecoration *hfdecoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@(0.5) color:[UIColor whiteColor]];
    [atti yy_setTextUnderline:hfdecoration range:hfrange];
    
    [atti yy_setTextHighlightRange:NSMakeRange(dyrange.location - 1, dyrange.length + 2) color:UIColor.whiteColor backgroundColor:UIColor.clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        WebViewController *controller = [[WebViewController alloc] initWithtitle:LocalizedString(@"订阅协议") WithUrl:@"https://docs.qq.com/doc/DRmlaV0lxYlhjU1Bw"];
        [[MYGlobal share].lastVC.navigationController pushViewController:controller animated:YES];
    }];
    YYTextDecoration *dydecoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@(0.5) color:[UIColor whiteColor]];
    [atti yy_setTextUnderline:dydecoration range:dyrange];

    tipLabel.attributedText = atti;
    scrollview.contentSize = CGSizeMake(MY_Screen_W, ctipLabel.bottom + 250);
    
    UIButton *duihuanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    duihuanBtn.layer.cornerRadius = 25;
    duihuanBtn.backgroundColor = MyColor(@"#FCD17E");
    [self.view addSubview:duihuanBtn];
    [duihuanBtn setTitle:LocalizedString(@"立即购买") forState:UIControlStateNormal];
    [duihuanBtn addTarget:self action:@selector(gotoPay) forControlEvents:UIControlEventTouchUpInside];
    duihuanBtn.titleLabel.font = MY_SCALE_SemiboldFONT(16);
    [duihuanBtn setTitleColor:MyColor(@"#5C3709") forState:UIControlStateNormal];
    [duihuanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.equalTo(self.view).offset(-15);
        make.height.mas_equalTo(45);
        make.bottom.equalTo(self.view.mas_bottom).offset(-12 - SafeBottomMargin);
    }];
}

- (void)verifyPurchaseWithPaymentTransaction:(SKPaymentTransaction *)transaction{
    //交易验证
    [QMUITips showLoading:LocalizedString(@"恢复购买中...") inView:self.view];
    NSURL *recepitURL = [[NSBundle mainBundle] appStoreReceiptURL];
    NSData *receipt = [NSData dataWithContentsOfURL:recepitURL];
    if(!receipt){
        return;
    }
    DLog(@"data==%@",[receipt base64EncodedStringWithOptions:0]);
    NSDictionary *paras =@{
        @"receipt":[receipt base64EncodedStringWithOptions:0]
    };
    [[HttpHelper sharedInstance] sendPost:@"api/pay/restore" parameters:paras success:^(NSURLSessionTask * _Nonnull operation, ResponseModel * _Nonnull responseObject) {
        [QMUITips hideAllTips];
        DLog(@"payfinish===%@",responseObject.data);
        if (responseObject.code == 1) {
            [[UserInfoManager sharedManager] getUserInfoData:^(BOOL flag) {
                
            }];
            [QMUITips showSucceed:LocalizedString(@"恢复购买成功！")];
        }else{
            [QMUITips showError:LocalizedString(@"无可恢复购买的项目!")];
        }
        [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    } failure:^(NSURLSessionTask * _Nonnull operation, NSError * _Nonnull error) {
        [QMUITips hideAllTips];
        [QMUITips showError:LocalizedString(@"无可恢复购买的项目!")];
        [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    }];
}

-(void)btnClick:(UIButton *)sender{
    for (UIButton *btn in btns) {
        btn.backgroundColor = MyColor(@"#465A95");
        ((UILabel *)[btn viewWithTag:10000]).textColor = UIColor.whiteColor;
        ((UILabel *)[btn viewWithTag:10001]).textColor = UIColor.whiteColor;
    }
    sender.backgroundColor = MyColor(@"#027AFF");
    selectIndex = sender.tag - 1000;
}

-(void)gotoPay{
    if(selectIndex < 0){
        return;
    }
    DLog(@"eeee===%ld",(long)selectIndex);
    NSDictionary *dic = contentArray[selectIndex];
    //检查是否可以购买
    __weak typeof(self) weakSelf = self;
    [[HttpHelper sharedInstance] sendGet:@"api/pay/check" parameters:@{@"productId":dic[@"product_id"]} success:^(NSURLSessionTask * _Nonnull operation, ResponseModel * _Nonnull responseObject) {
        __strong typeof(weakSelf) strongSelf = weakSelf;
        if(responseObject.code == 1){
            [QMUITips showLoading:LocalizedString(@"购买中...") inView:self.view];
            [[IAPShare sharedHelper].iap requestProductsWithCompletion:^(SKProductsRequest* request,SKProductsResponse* response)
             {
                if(response > 0 ) {
                    SKProduct* product = nil;
                    for(SKProduct *pro in response.products){
                        if([pro.productIdentifier isEqualToString:dic[@"product_id"]]){
                            if([pro.productIdentifier isEqualToString:[UserInfoManager sharedManager].vip_product_id]){
                                [QMUITips hideAllTips];
                                [QMUITips showInfo:LocalizedString(@"已购买过或暂时无法购买")];
                                return;
                            }
                            NSLog(@"Price: %@",[[IAPShare sharedHelper].iap getLocalePrice:pro]);
                            product = pro;
                            break;
                        }
                    }
                    
                    if(!product){
                        [QMUITips hideAllTipsInView:strongSelf.view];
                        return;
                    }
                    [[IAPShare sharedHelper].iap buyProduct:product
                                               onCompletion:^(SKPaymentTransaction* trans){
                        
                        if(trans.error)
                        {
                            NSLog(@"Fail %@",[trans.error localizedDescription]);
                            [QMUITips hideAllTipsInView:strongSelf.view];
                        }else if(trans.transactionState == SKPaymentTransactionStatePurchased) {
                            
                            //交易验证
                            NSURL *recepitURL = [[NSBundle mainBundle] appStoreReceiptURL];
                            NSData *receipt = [NSData dataWithContentsOfURL:recepitURL];
                            if(!receipt){
                                [QMUITips hideAllTipsInView:strongSelf.view];
                                return;
                            }
                            DLog(@"data==%@",[receipt base64EncodedStringWithOptions:0]);
                            NSDictionary *paras =@{
                                @"receipt":[receipt base64EncodedStringWithOptions:0],
                                @"productId":dic[@"product_id"],
                                @"transactionId":trans.transactionIdentifier
                            };
                            DLog(@"paras===%@",paras);
                            [MobClick event:@"dingyue" attributes:@{@"type" : product.productIdentifier, @"quantity" : [[IAPShare sharedHelper].iap getLocalePrice:product]}];
                            NSString *url = @"api/pay/subscribe";
                            if([dic[@"product_id"] isEqualToString:@"com.wuyuan.shuiyin.yongjiu"]){
                                url = @"api/pay/nonConsumable";
                            }
                            [DWKeychainTool saveItem:[receipt base64EncodedStringWithOptions:0] key:@"onlypay1"];
                            [[HttpHelper sharedInstance] sendPost:url parameters:paras success:^(NSURLSessionTask * _Nonnull operation, ResponseModel * _Nonnull responseObject) {
                                DLog(@"payfinish===%@",responseObject.data);
                                [QMUITips hideAllTipsInView:strongSelf.view];
                                if (responseObject.code == 1) {
                                    [QMUITips showSucceed:LocalizedString(@"成功！")];
                                    [[UserInfoManager sharedManager] getUserInfoData:^(BOOL flag) {
                                        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                                            [strongSelf.navigationController popViewControllerAnimated:YES];
                                        });
                                    }];
                                }else{
                                    [QMUITips showError:LocalizedString(@"已购买过或暂时无法购买")];
                                }
                            } failure:^(NSURLSessionTask * _Nonnull operation, NSError * _Nonnull error) {
                                [QMUITips hideAllTipsInView:strongSelf.view];
                                [QMUITips showSucceed:LocalizedString(@"购买失败")];
                            }];
                            
                        }else if(trans.transactionState == SKPaymentTransactionStateFailed) {
                            [QMUITips hideAllTipsInView:strongSelf.view];
                            NSLog(@"Fail");
                        }
                    }];//end of buy product
                }
            }];
        }else{
            [QMUITips showError:responseObject.message];
        }
    } failure:^(NSURLSessionTask * _Nonnull operation, NSError * _Nonnull error) {
        
    }];
    
}

@end
